import dao.UserDao;
import demo.Role;
import entity.User;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import demo.HelloSpring;
import service.UserService;

public class test {


    //上机1
    @Test
    public void testName() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        Role name = (Role) context.getBean("Name");
        System.out.println(name.getName() + ":" + name.getDialogue());

        name = (Role) context.getBean("Name2");
        System.out.println(name.getName() + ":" + name.getDialogue());
    }


    @Test
    public void testHelloSpring() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        HelloSpring helloSpring = (HelloSpring) context.getBean("helloSpring");
        helloSpring.print();
    }

    @Test
    public void printerTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        Printer printer = (Printer) context.getBean("printer");

        String content = "f;skhaklfhasdf;hsKFHA;HG;DKHA;LSKDJK;SGHJAK;L;;;H;;;ASD;HGIODSAP;IGH;LKEHJW;EHFDSIODFHK;ADLSJGDSOIAHG;DKLSAHKSDL;GHDA;KLSHKEJR;LWHG;LSDAHVNDKF;AHEIOR;GHTDIS;LAJKJGDL;KSAJHG";
        printer.print(content);
    }

    @Test
    public void aopTest() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        UserService service = (UserService) context.getBean("userService");

        User user = new User();
        user.setId(1);
        user.setUserName("test");
        user.setPassword("123456");
        user.setEmail("123@xxx.com");
        service.save(user);
    }

    @Test
    public void aopTes2t() {
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        User User = (User) context.getBean("user");

        System.out.println(User);


    }
}


